class Node:
    def __init__(self, data):
        # 初始化节点类，包含节点数据和下一节点的指针
        self.data = data  # 数据
        self.next = None  # 指针


class LinkList:
    def __init__(self):
        self.head = Node(None)

    def create(self, a):
        tail = self.head
        for i in range(len(a)):
            p = Node(a[i])
            tail.next = p
            tail = p

    def output(self):
        p = self.head.next
        while p != None:
            print(p.data, end=' ')
            p = p.next
        print()

def merge(ha,hb):
    p = ha.head.next
    q = hb.head.next
    hc = LinkList()
    tail = hc.head=ha.head
    while p!=None and q!=None:
        if p.data<q.data:
            tail.next=p
            tail=p
            p=p.next
        elif p.data>q.data:
            tail.next=q
            tail=q
            q=q.next
        else:
            tail.next=p
            tail=p
            p=p.next
            q=q.next
    if p ==None:
        tail.next=q
    if q==None:
        tail.next=p
    return hc
    
h1=LinkList()
h1.create([14,16,19,22,23,31,33,67,68,75,76,78,81,91,95])
h2=LinkList()
h2.create([23,25,26,37,1245,2534252,34,1,432,534,32,66])
h=merge(h1,h2)
h.output()